/* goto parser expects ';' after label name */
label:
if (goto label;)
    print("a\n");

/* for expects ';' after expression */
label:
for (goto label;; goto label;;)
    ;

auto v[] = { 1, 2 };
print("%d\n", v[]);

label:
print("%d\n", goto label;);

/* the parser "filters" most cases already */
auto a = if (1) 2; else 3;

auto a = 1 2;

/* this one was being read as 'a = 22;' (22 is ';' token value) */
auto a =;;

/* this program must fail, preferably at compile time */
auto *a, m = 2;
void f(n)
{
    /* here is the problem.
     * References to local variables could be implemented
     * in a way that this would be safe, but then, cannot
     * "trace" the usage of the 'a', what could cause
     * undefined behavior if it is used after the function
     * have returned, so, should only allow local variables
     * "taking the address" of local variables, and also,
     * this value can only be passed as an argument to
     * other functions, but not be returned.
     */
    a = &n;
    print("%d\n", *a);
    *a = 5;
    print("%d\n", *a);
}
a = &m;
f(2);
print("%d\n", *a);	// <- here is the dangling pointer
*a = 4;
print("%d\n", *a);

/* another example that should be far easier to trigger at compile time */
auto *a;
auto *(f)(n)
{
    return &n;
}
a = f(2);
print("%d\n", *a);	// <- here is the dangling pointer


/* same example, but to check for proper non toplevel code */
auto *a;
auto *(f)(n)
{
    return &n;
}
void g(void)
{
    a = f(2);
    print("%d\n", *a);	// <- here is the dangling pointer
}
g();

/* again same example, but using a local pointer */
auto *(f)(n)
{
    return &n;
}
void g(void)
{
    auto *a = f(2);
    print("%d\n", *a);	// <- here is the dangling pointer
}
g();

/* this one is similar to previous one, and "could be allowed",
 * but the problem is that in the call to f() r is set to f().n,
 * but in g() it is setting g().n
 * FIXME this is currently being allowed, and the only way to
 * prevent it is to do something like keep track of t_localref
 * objects, and if a list of those exist, traverse it at every
 * function return, checking for invalid objects.
 */
auto v, *r = &v;
void f(n)
{
    r = &n;
}
f(0);
void g(n)
{
    print("%d\n", *r);
    *r = 1;
    print("%d\n", *r);
}
g(2);


// prototype of a function that returns an auto pointer
// the correct statement is:
//	typedef auto *(*pt_pf_t)(a);
typedef auto *pt_f_t(a);
// prototype of a function that returns a pointer to an auto pointer
// the correct statement is:
//	typedef auto **(*ppt_pf_t)(a);
typedef auto **ppt_f_t(a);
// prototype of a function that returns a vector
// the correct statement is:
//	typedef auto *v_pf_t(a);
typedef auto v_f_t(a)[];
// declaration of a vector of functions that returns an auto
// the correct statement is:
//	typedef auto *t_pfv_t[](a);
typedef auto t_fv_t[](a);
// declaration of a vector of functions that returns a vector
// the correct statement is:
//	typedef auto *v_vpf_t[](a)[];
typedef auto v_vf_t[](a)[];

auto v[(];

auto v[{1}];

{,}

{;,}

// this was being parsed using the token value
auto a =+;;

auto a += 2;

/* FIXME this is silently accepted */
auto a = a;

...[0];

void f() { ...[0]; }

void g(...) {}
void f(a, b, c, ...) { g(...); }

void f() { &...; }

/* compile time error */
void f(...)
{
    auto *a = &...[-2];
    print("%d\n", *a);
}

/* run time error */
void f(...)
{
    auto *a = &...[20];
    print("%d\n", *a);
}
f(1);

/* unfinished macro conditional */
#ifdef foo
print("foo\n");

/* this worked previously, but is incorrect as variables could also be changed */
auto f(v, ...)
{
    return v + ...[0];
}
void g()
{
    auto v = 1;
    /* previously, the unbound access in f would read g().v */
    if (f(v) == 2)	print("oops\n");
}
g();	/* and call it to cause the (runtime) failure */

/* run time error - exception not handled */
throw;

/* compile time error, goto leaving try (or entering catch) */
try {
    goto label;
}
catch (e) {
    label:;
}

/* compile time error, goto leaving try */
try {
    goto label;
}
catch (e) {
}
label:;

/* compile time error, goto leaving catch */
try {
}
catch (e) {
    goto label;
}
label:;

/* compile time error, goto entering try */
goto label;
try {
    label:;
}
catch (e) {
}

/* compile time error, goto entering catch */
goto label;
try {
}
catch (e) {
    label:;
}

/* runtime error write on constant vector
 * FIXME detectable at compile time */
string a = "foobar";
a[0] = 'F';

auto f() { return 1; }
auto a = f();
f();
auto b = a / 0;

auto f() { return 1; }
auto a = f();
auto b = a / 0;
